package com.teangtang.fly.controller;
import com.teangtang.fly.dto.TravellerDTO;
import com.teangtang.fly.entity.Province;
import com.teangtang.fly.entity.Traveller;
import com.teangtang.fly.service.TravellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/travellers")
public class TravellerController {

    @Autowired
    private TravellerService travellerService;

    @GetMapping
    public List<Traveller> getAllTravellers() {
        return travellerService.getAllTravellers();
    }

    @GetMapping("/{travellerId}")
    public Traveller getTravellerById(@PathVariable String travellerId) {
        return travellerService.getTravellerById(travellerId);
    }

    @PostMapping
    public ResponseEntity<TravellerDTO> createProvince(@RequestBody TravellerDTO travellerDTO) {
        TravellerDTO savedTraveller = travellerService.createTraveller(travellerDTO);
        return new ResponseEntity<>(savedTraveller, HttpStatus.CREATED);
    }

    @DeleteMapping("/{travellerId}")
    public void deleteTraveller(@PathVariable String travellerId) {
        travellerService.deleteTraveller(travellerId);
    }
}
